/**
 * MonitorAction.java
 * Created at 2018-1-4
 * Created by zhanghailin
 * Copyright (C) 2018 BROADTEXT SOFTWARE, All rights reserved.
 */
package com.broadtext.app.monitor.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.broadtext.app.monitor.service.MonitorService;
import com.broadtext.common.annotation.AppControllerAspect;
import com.broadtext.common.exp.DaoException;
import com.broadtext.common.utils.StringUtils;
import com.broadtext.rms.system.service.ISysUserService;

/**
 * <p>ClassName: MonitorAction</p>
 * <p>Description: TODO</p>
 * <p>Author: zhanghailin</p>
 * <p>Date: 2018-1-4</p>
 */
@Controller
@RequestMapping("/app/monitor")
public class MonitorAction {
    
    /**
     * 注入service
     */
    @Autowired
    @Qualifier("monitorService")
    private MonitorService monitorService;
    
    /**
     * 用户Service
     */
    @Autowired
    @Qualifier("sysUserService")
    private ISysUserService sysUserService;
    
    @AppControllerAspect
    @RequestMapping(value = "/getMonitorDataList.mvc")
    @ResponseBody
    public List<Object> getMonitorDataList(HttpServletRequest request, HttpServletResponse response) {
        List<Object> list = new ArrayList<Object>();
        Map<String, Object> params = new HashMap<String, Object>();
        //获取请求用户名
        String loginName = request.getParameter("loginName");
        //根据登录名获取查询参数
        String loginUserCusId = this.sysUserService.getCustomerId(loginName);
        if(loginUserCusId!=null&&StringUtils.isNotBlank(loginUserCusId)){
            params.put("cusId", loginUserCusId);
        }
        //获取cusId
        String cusId = request.getParameter("cusId");
        if(StringUtils.isNotBlank(cusId)){
            params.put("cusId", cusId);
        }
        //获取packCode
        String packCode = request.getParameter("packCode");
        if(StringUtils.isNotBlank(packCode)){
            params.put("packCode", packCode);
        }
        
        list = this.monitorService.getMonitorDataList(params);
        return list;
    }
    
    
    /**
     * 
     * <p>Description: 获取电池实时详细信息</p>
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/getBatteryDetailInfo.mvc")
    @ResponseBody
    public Map<String, Object> getBatteryDetailInfo(HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> data = new HashMap<String, Object>();
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("packCode", request.getParameter("packCode"));
        params.put("colClientId", request.getParameter("colClientId"));
        data = this.monitorService.getBatteryDetailInfo(params);
        return data;
    }
    
    /**
     * 
     * <p>Description: 查询电池电压和温度数据</p>
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/getBatteryVolAndTempData.mvc")
    @ResponseBody
    public Map<String, Object> getBatteryVolAndTempData(HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> data = new HashMap<String, Object>();
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("packCode", request.getParameter("packCode"));
        params.put("colClientId", request.getParameter("colClientId"));
        List<Object> volList = this.monitorService.getBatteryVolData(params);
        List<Object> tempList = this.monitorService.getBatteryTempData(params);
        data.put("volData", volList);
        data.put("tempData", tempList);
        return data;
    }
    
    
    @RequestMapping(value = "/getCustomerOptions.mvc")
    @ResponseBody
    public List<Object> getCustomerOptions(HttpServletRequest request, HttpServletResponse response) {
        List<Object> list = new ArrayList<Object>();
        list = this.monitorService.getCustomerOptions(null);
        return list;
    }

}
